/* File name     :  nfivi_map.h
 * Author        :  Wentao Shang
 * 
 * Contents      :
 *    This file is the header file for the 'nfivi_map.c' file,
 *    which contains all the system header files and definitions
 *    used in the 'nfivi_map.c' file.
 *
 */

#ifndef NFIVI_MAP_H
#define NFIVI_MAP_H

#include <linux/module.h>

#include <linux/time.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/spinlock.h>

/* map item structure */
struct map_tuple {
	struct list_head node;
	unsigned short oldport;
	unsigned short newport;
	struct timeval timer;
};

/* map list structure */
struct map_list {
	spinlock_t lock;
	struct list_head chain;
};

/* map-used global variables */
extern unsigned int Mod;
extern unsigned int Res;
extern unsigned int Current;
extern int AutoConfig;

extern struct map_list MapList;
extern time_t TimeOut;

/* list operations */
extern void init_map_list(struct map_list *list);
extern unsigned int get_list_size(struct map_list *list);
extern int port_in_use(unsigned int port, struct map_list *list);
extern struct map_tuple* add_new_map(unsigned short oldp, unsigned short newp, struct map_list *list);
extern void refresh_map_list(struct map_list *list);
extern void free_map_list(struct map_list *list);

/* mapping operations */
extern unsigned short get_outflow_map_port(unsigned short oldp, struct map_list *list);
extern unsigned short get_inflow_map_port(unsigned short newp, struct map_list *list);

#endif

